package com.util.orm.util.impl;

import com.util.orm.util.ShardingKeyBuilder;
import org.springframework.stereotype.Component;

@Component
public class OrderNoShardingKeyBuilder implements ShardingKeyBuilder {

    @Override
    public String getDBShardingKey(Object param) {
        String dataSource = null;
        String orderNo = param.toString();
        if(orderNo != null) {
            int hstoreId = Integer.parseInt(orderNo.substring(orderNo.length() - 2));
            dataSource = "order" + hstoreId % 20;
        }
        return dataSource;
    }
}
